/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-05     Administrator       the first version
 */

#include "Log.h"
#include "GlobalVar.h"

/* rt-os包含文件  */
#include <rtthread.h>
#include <rtdbg.h>
#include <cstring>

/*
 * 日志消息队列协议
 *
 *  名称0-9 10字节      类型10   类型11   状态12     参数
 *
 *                 任务 1     1创建        失败-1     超时时间
 *                 信号量2    2启动       不关心0
 *                           3释放        成功1
 *                           4接收        超时-2
 *                           5删除
 */

void Log()
{
    LOG log_msg;
    static char logContent[100];
    /* 接收消息  */
    rt_mq_recv(LogMqHandle, &log_msg, 20, RT_WAITING_FOREVER);
    /* 拼接消息  */
    strcpy(logContent,(const char*)log_msg.name);

    switch(log_msg.type)
    {
        case 1:
            strcat(logContent," task");
            break;

    }

    switch(log_msg.act)
    {
        case 1:
            strcat(logContent," create");
            break;
        case 2:
            strcat(logContent," startup");
            break;

    }

    switch(log_msg.state)
    {
        case -1:
            strcat(logContent," failed");
            break;
        case 0:
            strcat(logContent," ");
            break;
        case 1:
            strcat(logContent," successed");
            break;

    }

    switch(log_msg.para)
    {
        case 0:
            strcat(logContent,".");
            break;
        default:
            //strcat(logContent,"%d ms.",log_msg.para);
            break;

    }
    /* 日志打印 */
    if(log_msg.state >= 0)
    {
        LOG_D(logContent);
    }
    else
    {
        LOG_E(logContent);
    }
    /* 日志延时 */
    rt_thread_mdelay(50);
}


void Log_Task(void *parameter)
{
    while(1)
    {
        Log();
    }
}
